package 队列与栈;

import java.util.LinkedList;
import java.util.Queue;

class 用队列实现栈 {
    Queue<Integer> q;
    Queue<Integer> q2;

    public 用队列实现栈() {
        q = new LinkedList<>();
        q2 = new LinkedList<>();
    }

    public void push(int x) {
        q2.offer(x);
        while (!q.isEmpty()) {
            q2.offer(q.poll());
        }
        Queue<Integer> temp = q2;
        q2 = q;
        q = temp;
    }

    public int pop() {
        return q.poll();
    }

    public int top() {
        return q.peek();
    }

    public boolean empty() {
        return q.isEmpty();
    }
}

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack obj = new MyStack();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.top();
 * boolean param_4 = obj.empty();
 */
